package com.hlj.ncp.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hlj.ncp.finance.entity.Order;
import com.hlj.ncp.finance.mapper.OrderMapper;
import com.hlj.ncp.finance.service.IOrderService;
import com.hlj.ncp.common.utils.HljStringUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 订单信息Service业务层处理
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    /**
     * 查询订单信息列表
     * 
     * @param order 订单信息
     * @return 订单信息
     */
    @Override
    public List<Order> selectOrderList(Order order) {
        LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>();
        if (order != null) {
            // 条件过滤
            if (HljStringUtils.isNotBlank(order.getOrderCode())) {
                queryWrapper.eq(Order::getOrderCode, order.getOrderCode());
            }
            if (HljStringUtils.isNotBlank(order.getOrderType())) {
                queryWrapper.eq(Order::getOrderType, order.getOrderType());
            }
            if (order.getCustomerId() != null) {
                queryWrapper.eq(Order::getCustomerId, order.getCustomerId());
            }
            if (order.getSupplierId() != null) {
                queryWrapper.eq(Order::getSupplierId, order.getSupplierId());
            }
            if (HljStringUtils.isNotBlank(order.getPayStatus())) {
                queryWrapper.eq(Order::getPayStatus, order.getPayStatus());
            }
            if (HljStringUtils.isNotBlank(order.getDeliveryStatus())) {
                queryWrapper.eq(Order::getDeliveryStatus, order.getDeliveryStatus());
            }
            if (HljStringUtils.isNotBlank(order.getStatus())) {
                queryWrapper.eq(Order::getStatus, order.getStatus());
            }
        }
        return list(queryWrapper);
    }

    /**
     * 查询订单信息详细
     * 
     * @param orderId 订单ID
     * @return 订单信息
     */
    @Override
    public Order selectOrderById(Long orderId) {
        return getById(orderId);
    }

    /**
     * 新增订单信息
     * 
     * @param order 订单信息
     * @return 结果
     */
    @Override
    public boolean insertOrder(Order order) {
        return save(order);
    }

    /**
     * 修改订单信息
     * 
     * @param order 订单信息
     * @return 结果
     */
    @Override
    public boolean updateOrder(Order order) {
        return updateById(order);
    }

    /**
     * 批量删除订单信息
     * 
     * @param orderIds 需要删除的订单ID
     * @return 结果
     */
    @Override
    public boolean deleteOrderByIds(Long[] orderIds) {
        return removeByIds(Arrays.asList(orderIds));
    }

    /**
     * 删除订单信息信息
     * 
     * @param orderId 订单ID
     * @return 结果
     */
    @Override
    public boolean deleteOrderById(Long orderId) {
        return removeById(orderId);
    }
} 